var SwordCollapse = new Class({
     Implements:[Options,Events],
	 name: "SwordCollapse",
    options:{
		pNode:null,
		name:"collapse",
    	widgetName:null,
    	caption:"",
    	collapse:"false"
    },a:null,
    container:null,
    collapseDiv:null,
	 initialize: function(options){
		  this.setOptions(options);
	     },
    initParam:function(initPara) {
    	 this.htmlOptions(initPara);
    	this.build();
    },
    build:function() {
    	 this.container = this.options.pNode;
//    	var  headerDiv = new Element('div',{
//             'class':'SwordCollapse_header',
//             'text':this.options.caption,
//             'name':this.options.name
//         }).inject(this.container);
//    	 this.collapseDiv = new Element('div',{
//             'class':'x-tool',
//         }).inject(headerDiv);
    	 if(!this.options.widgetName) return;
    	 var wgts = this.options.widgetName.split(",");
    	
    	 if(this.options.collapse=="true"){
    		 wgts.each(function(e){
    			 $w(e).display();
    		 });
    	 }
//    		 
//    		 this.collapseDiv.addClass("x-tool-s");
//    		 this.collapseDiv.set("title","展开");
//    	 }else  {
//    		 this.collapseDiv.removeClass("x-tool-s");
//    		 this.collapseDiv.set("title","收缩");
//    		 }
    	 
    	 var p= this;
    	 this.collapseDiv=this.options.pNode.getElements("div div")[0];
    	 this.collapseDiv.addEvent('click', function(e) {
    		p.toggle();
    	 });
    	 if(Browser.Engine.trident5&&this.options.caption==""){//ie7下面收缩按钮被挤下去的问题
    		 this.collapseDiv.setStyle("margin-top","3px");
    	 }
    },//不用display和undisplay(这俩方法是addClass) 因为压缩后演示被冲掉了
    collapse:function(widgetName) {
    	if(!widgetName) widgetName=this.options.widgetName;
    	var wgts = widgetName.split(",");
    	 wgts.each(function(e){
			 //$w(e).display();
    		 $w(e).options.pNode.setStyle("display","");
		 });
    	 this.collapseDiv.set("title","展开");
    	 this.collapseDiv.addClass("x-tool-s");
    },
    extend:function(widgetName) {
    	if(!widgetName) widgetName=this.options.widgetName;
    	var wgts = widgetName.split(",");
    	 wgts.each(function(e){
			 //$w(e).undisplay();
    		 $w(e).options.pNode.setStyle("display","");
		 });
    	 this.collapseDiv.set("title","收缩");
    	 this.collapseDiv.removeClass("x-tool-s");
    },
    toggle:function(widgetName){
    	if(!widgetName) widgetName=this.options.widgetName;
    	var wgts = widgetName.split(",");
    	if(this.collapseDiv.hasClass("x-tool-s")){
    		 this.collapseDiv.set("title","收缩");
    		 this.collapseDiv.removeClass("x-tool-s");
    		 wgts.each(function(e){
    			 $w(e).options.pNode.setStyle("display","");
    			 //$w(e).undisplay(); 
    		 });
    	}else{
    		 this.collapseDiv.set("title","展开");
    		this.collapseDiv.addClass("x-tool-s");
    		 wgts.each(function(e){
    			 $w(e).options.pNode.setStyle("display","none");
    			 //$w(e).display();
    		 });
    	}
    }
   
});



